package com.proxy.http.proxy;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;

import com.proxy.dao.Proxy;
import com.proxy.util.Constants;
/**
 * Handle checking google host class.
 *
 */
public class ClientExecuteProxyCheckOtherHost extends ClientExecuteProxy{

	public ClientExecuteProxyCheckOtherHost(HttpClient httpclient,Proxy myProxy) throws URISyntaxException {
		super(httpclient,myProxy, getHttpGet());
	}
	
	public ClientExecuteProxyCheckOtherHost(HttpClient httpclient,Proxy myProxy,HttpGet httpGet) throws URISyntaxException {
		super(httpclient,myProxy, httpGet);
	}
	
	private static HttpGet getHttpGet() throws URISyntaxException
	{
		URIBuilder builder = new URIBuilder();
//		builder.setScheme("http").setHost("ajax.googleapis.com").setPath("/ajax/services/search/web")
		builder.setScheme("http").setHost(Constants.OTHER_HOST_NAME);
		URI uri = builder.build();
		HttpGet httpGet = new HttpGet(uri);
//		req.setHeader("User-Agent", 
//					"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
		return httpGet;
	}


	/**
	 * get valid display string for valid google proxy.
	 */
	public String getValidDisplayString() {
		return " (passed)";
	}

	/**
	 * get valid indisplay string for invalid other proxy.
	 */
	public String getInvalidDisplayString() {
		return " (failed)";
	}


	/**
	 * update validForOtherHost to true for myProxy object
	 * set the update time in myProxy object.
	 */
	public void updateResultByValid(Proxy myProxy) {
		myProxy.setValidForOtherHost(true);
		myProxy.setUpdateTimeForOtherHost(new Date());
	}


	/**
	 * update validForOtherHost 
	 * to false for myProxy object
	 */
	public void updateResultByInvalid(Proxy myProxy) {
		myProxy.setValidForOtherHost(false);
	}


	public String[] getRegexString() {
		return Constants.OTHER_REGEX_STRING;
	}

	public int getVisitPageDelay() {
		return 10000;
	}

	public void setValidOutputMessage(String message) {
		System.out.println(message);
	}

	public void setInValidOutputMessage(String message) {
		System.out.println(message);
	}

}